import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 从N到最接近他的斐波那契数共需要几步
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N == 1 || N == 2) {
            System.out.println(0);
            return;
        }
        int a = 0;
        int b = 1;
        int c = 1;
        while(N > c) {
            a = b;
            b = c;
            c = a + b;
        }
        int ans = Math.min(Math.abs(c - N),Math.abs(b - N));
        System.out.println(ans);
    }
}
